#include<iostream>
#include<fcntl.h>
#include <sstream>
#include <string.h>
#include<vector>
#include<fstream>
#include<map>
#include<stdlib.h>

using namespace std;

class ShellRC {
	private:
	map<string, string> env_variables;
	public :
	ShellRC () {
		string file = "/tmp/.shellrc";		
		loadFile(file.c_str());				
	}	

	void loadFile(const char * file) {
		vector<string> lines;
		ifstream ifs(file);
		string temp;
		string tokens[2];
		while(getline(ifs, temp)) {
			lines.push_back(temp);
		}
		for (int i=0;i<lines.size();i++) {
			string temp = lines[i];
			split(temp, '=', tokens);
			if (tokens !=NULL) {
				setValue(tokens[0], tokens[1]);
			}	
		}
	}

	void split(string str, char separator, string * tokens) {
		stringstream ss(str);
		string s;
		int i = 0;
		while (getline(ss, s, separator) && i < 2) {
			tokens[i] = s;
			i++;
		}
		if (i != 2) {
			tokens = NULL;
			return;
		} 
		return;
	}

	string getValue(string key) {
		map<string,string>::iterator it;
		it = env_variables.find(key);
		if (it != env_variables.end()) {
			return it->second;
		} else {
			char* p = getenv(key.c_str());
			if(p!=NULL) return p;
		}
		return "";
	}
	
	void setValue(string key, string value) {
		map<string,string>::iterator it = env_variables.find(key);
		if(it != env_variables.end()) {
			env_variables.erase(it);
		}
		env_variables.insert(std::make_pair(key, value));
	}
};


